/*
 * DS1306.c
 *
 *  Created on: Jan 21, 2012
 *      Author: Administrator
 */
#include "DS1306.h"

//inline uint8_t RTCTransfer( uint8_t aReg, uint8_t aDat )
//{
//   uint8_t spiByte;
//
//   // Clear SPIE bit if set
//   spiByte = SPSR;
//   spiByte = SPDR;
//
//   // Set CS to high to enable DS1306
//   SPI_DDR |= _BV(SS_bp);
//
//   // Send register, then send/read data
//   transferSPI( aReg );
//   spiByte = transferSPI( aDat );
//
//   // Set CS to low to disable DS1306
//   SPI_DDR &= ~_BV(SS_bp);
//
//   return spiByte;
//}

//inline void WriteRTC( uint8_t aReg, uint8_t aDat )
//{
//   RTCTransfer( aReg, aDat );
//}
//
//inline uint8_t ReadRTC( uint8_t aReg )
//{
//   return RTCTransfer( aReg, 0 );
//}
//
//inline uint8_t getSeconds()
//{
//	uint8_t ret = ReadRTC(SEC_R);
//	uint8_t tens = ((ret & SEC10_MASK)>>4)*10;
//	uint8_t ones = ret & SEC_MASK;
//	return (tens+ones);
//}
//inline uint8_t getSecondsHex()
//{
//	return ReadRTC(SEC_R);
//}
//
//inline uint8_t getMinutes()
//{
//	uint8_t ret = ReadRTC(MIN_R);
//	uint8_t tens = ((ret & MIN10_MASK)>>4)*10;
//	uint8_t ones = ret & MIN_MASK;
//	return(tens+ ones);
//}
//inline uint8_t getMinutesHex()
//{
//	return ReadRTC(MIN_R);
//}
//
//inline uint8_t getHours()
//{
//	uint8_t ret = ReadRTC(HOUR_R);
//	uint8_t tens = ((ret & HOURS10_MASK)>>4)*10;
//	uint8_t ones = ret & HOURS_MASK;
//	return(tens+ ones);
//}
//inline uint8_t getHoursHex()
//{
//	uint8_t ret = ReadRTC(HOUR_R);
//	return (ret & 0x1F);
//}
//
//inline uint8_t getAMPM()
//{
//	uint8_t ret = ReadRTC(HOUR_R);
//	if((ret & AM_PM_MASK))
//	{
//		return 1;
//	}
//	else
//	{
//		return 0;
//	}
//}
//input in hex
//ex:
//	seconds = 0x38 (38 seconds)
//	minutes = 0x49 (49 minutes)
//	hours   = 0x11 (11 hours)
// AM = 0, PM = 1
void setTime(uint8_t seconds, uint8_t minutes, uint8_t hours, uint8_t AMPM)
{
	WriteRTC(SEC_W, seconds);
	WriteRTC(MIN_W, minutes);
	WriteRTC(HOUR_W, hours | (AMPM<<AM_PM_bp) | (1<<6));
}

